package com.example.mvpdemo.presenter;

import com.example.mvpdemo.IView;
import com.example.mvpdemo.MainActivity;
import com.example.mvpdemo.model.Callback;
import com.example.mvpdemo.model.IModel;
import com.example.mvpdemo.model.MainModel;
import com.example.mvpdemo.model.User;

public class MainPresenter implements IPresenter, Callback {
    private IView mainView;
    private IModel mainModel;

    public MainPresenter(IView mainView){
        mainModel = new MainModel();
        this.mainView = mainView;
    }
    @Override
    public void login(String username, String password) {
        mainView.showPregress();
        mainModel.login(username,password,this);
    }

    @Override
    public void onSuccess(User user) {
        mainView.hidePregress();
        mainView.loginSucess(user);
    }

    @Override
    public void onFailure(String msg) {
        mainView.hidePregress();
        mainView.loginFailure(msg);
    }
}
